<?php

declare (strict_types=1);

namespace app\common\model;


use cores\BaseModel;
use think\facade\Log;

/**
 * 广告位模型
 * Class Article
 * @package app\common\model
 */
class Advertising extends BaseModel
{
    // 定义表名
    protected $name = 'advertising';

    // 定义主键
    protected $pk = 'id';

    //广告位详情
    public function detail($type): array
    {
        $detail = [];
        $ad = (new static)->where('type','=',$type)
            ->order('id','desc')
            ->find();
        if($ad){
            $detail = $ad->toArray();
            $tmp = json_decode($detail['value'],true);
            foreach ($tmp as &$item){
                $img_info = UploadFile::detail($item['image_id'])->toArray();
                $item['image_url'] = $img_info['preview_url'];
            }
            $detail['value'] = $tmp;
        }
        return $detail;
    }

}
